#pragma once
#include "CybertronBridgeTaskBaseInterface.hpp"
#include "cybertron/DefinesCore.hpp"
#include "Sensor/SensorCommon.pb.h"
#include <atomic>
#include <string>

CYBERTRON_BEGIN

class CybertronBridgeTaskBase : public CybertronBridgeTaskBaseInterface
{
public:
	CybertronBridgeTaskBase();
	virtual ~CybertronBridgeTaskBase();

	/**
	* Function:
	*	reset
	* Brief:
	*	Reset the task, End,then start this task again.
	* Parameters:
	*	none
	* Return:
	*	none
	*/
	void reset();

	/**
	* Function:
	*	SetNoPause
	* Brief:
	*	Set no pause, then this node will ignore pause command from time server
	* Parameters:
	*	on: state
	* Return:
	*	none
	*/
	void SetNoPause(bool on) { mNoPause = on; }
	bool noPause() { return mNoPause; }

protected:

	friend class CybertronBridgeBase;
	friend class CybertronWebBridge;

	enum TaskState
	{
		STATE_IDLE,
		STATE_RUNNING,
		STATE_END,
		STATE_PAUSE,
		STATE_RESET
	};
	void fromBridgePlay();
	void fromBridgePause();
	void fromBridgeReset();
	void fromBridgeEnd();

	void tryStartTask();
	void run(float speed);
	std::atomic<TaskState> mState;
	std::atomic<bool> mNoPause;
};

CYBERTRON_END